package characterCreator;

import java.util.Random;

public class Elf extends Character{
	private int[] expTable = 	{ 0,0,4000,8000,16000,32000,64000,120000,250000,400000,			// DONE!
								600000,850000,1100000,1350000,1600000,1850000,2100000,
								2350000,2600000,2850000,3100000};
	
	private int[] toHitTable = 	{ 20,19,19,19,17,17,17,15,15,15,13,12,11,10,9,8,				// DONE!
								7,6,5,4,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
	
	private int[] svPoison = 	{ 16,12,12,12,8,8,8,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,				// DONE!
								2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
	
	private int[] svMagicWand = { 16,13,13,13,10,10,10,7,7,7,4,4,4,2,2,2,2,2,2,2,2,2,			// DONE!
								2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
	
	private int[] svParalysis = { 16,13,13,13,10,10,10,7,7,7,4,4,4,2,2,2,2,2,2,2,2,2,			// DONE!
								2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
	
	private int[] svDragon = 	{ 19,15,15,15,11,11,11,7,7,7,3,3,3,2,2,2,2,2,2,2,2,2,			// DONE!
								2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
	
	private int[] svSpell = 	{ 19,15,15,15,11,11,11,7,7,7,3,3,3,2,2,2,2,2,2,2,2,2,			// DONE!
								2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };

	
	public Elf() {
		this.setType(ClassType.Elf);
		
		for (Abilities a : Abilities.values()) {
			this.setAbility(a, 0);
		}
		
		this.setPrimeRequisite(Abilities.Strength, 0);
		this.setPrimeRequisite(Abilities.Intelligence, 1);
		
		this.setLevel(0);
		this.setAC(10);
	}
	
	public Elf(Character currentCharacter) {
		this.setType(ClassType.Elf);
		
		this.setName(currentCharacter.getName());
		this.setPlayer(currentCharacter.getPlayer());
		this.setSex(currentCharacter.getSex());
		this.setAlignment(currentCharacter.getAlignment());
		
		for (Abilities a : Abilities.values()) {
			this.setAbility(a, currentCharacter.getAbility(a));
		}
		
		this.setPrimeRequisite(Abilities.Strength, 0);
		this.setPrimeRequisite(Abilities.Intelligence, 1);
		
		this.setLevel(currentCharacter.getLevel());
		this.setAC(currentCharacter.getAC());
	}
	
	public void setLevel(int level) {
		
		Random random = new Random(System.currentTimeMillis());
		
		this.level = level;
		
		System.out.println("level was set to " + level);
		
		if (level <= 8) {
			this.setHP(new Die().Roll(level, 6));
		} else {
			this.setHP((new Die().Roll(8, 6)+2*level));
		}
	
		this.setExp(expTable[level]);
		
		this.setExpBonus();
		
		System.out.println("EXP: " + this.getExp());
		
		this.setTHAC0(toHitTable[level]);
		
		for (SavingThrow a : SavingThrow.values()) {
			this.setSave(a, getSaveTable(a)[level]);
		}
	}
	
	public int[] getSaveTable(SavingThrow a) {
		switch (a) {
		case svPoison:
			return svPoison;
		case svMagicWand:
			return svMagicWand;
		case svParalysis:
			return svParalysis;
		case svDragon:
			return svDragon;
		case svSpell:
			return svSpell;
		}
		return null;
	}
}
 